import router from './router'
import store from './store'
import NProgress from 'nprogress' // Progress 进度条
import 'nprogress/nprogress.css'// Progress 进度条样式
import {Message} from 'element-ui'
import {getToken} from '@/utils/auth' // 验权

router.beforeEach((to, from, next) => {
  //获取session中的user
  const userFlag =  window.sessionStorage.getItem('user');
  //碰到login登陆页面直接放行
  if(to.path === '/login') {
    // 如已登录，不进入登录页
    if (userFlag) return next('/')
    return next();
  }

  //判断
  if(!userFlag) return next('/login');
  //无值，返回到登陆页面
  next(); //符合要求不拦截
})

router.afterEach(() => {
  NProgress.done() // 结束Progress
})
